package com.tvein.sanguo.action.controller.system
{
	//flash
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.action.view.ActionMediator;
//
	public class ActionClose extends SimpleFabricationCommand implements ICommand
	{
		private var actionMediator:ActionMediator;
		
		override public function execute(notification:INotification) : void
		{
			actionMediator = facade.retrieveMediator(ActionMediator.NAME) as ActionMediator;
			
			var i:int;
			
			if (notification.getBody() == "*")
			{
				for (i = actionMediator.action.numChildren - 1; i >= 0; i--)
				{
					var actionName:Array = actionMediator.action.getChildAt(0).name.split("-");
					
					switch (actionName[0]) 
					{
						case "Skill":
							if(actionName[1] != "0")
							{
								actionMediator.action.removeChildAt(0);
							}
							break;
						case "Room":
							break;
						default:
							actionMediator.action.removeChildAt(0);
					}
				}
			}
			else
			{
				for (i = actionMediator.action.numChildren - 1; i >= 0; i--)
				{
					if (actionMediator.action.getChildAt(i).name == notification.getBody())
					{
						actionMediator.action.removeChildAt(i);
					}
				}
			}
		}
	}
}